//
//  LRTabViewController.swift
//  LRXinaWeibo
//
//  Created by 123 on 16/4/15.
//  Copyright © 2016年 123. All rights reserved.
//

import UIKit

class LRTabViewController: UITabBarController {

    func composeDidClick(){
        print("打印方法")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 0|由于tabbar是只读，不能够直接操作，如果要修改 可以使用kvc
        let mainTabBar = LRMainTabBar()
        setValue(mainTabBar, forKey: "tabBar")

        // 1|添加子视图控制器
        addChildViewControllers()
        
        // 打印函数的类名
        print(tabBar.classForCoder)
        
        // 2| 设置点击事件
        mainTabBar.composeBtn.addTarget(self, action: #selector(LRTabViewController.composeDidClick), forControlEvents: UIControlEvents.TouchUpInside)
    }
// 私有的方法，只能在本类可以调用
    private func addChildViewControllers(){
    
        addChildViewController(LRHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(LRMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(LRDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(LRProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
        
    }
    
    // 重载 (重写系统方法，但是参数不一样)
    private func addChildViewController(vc: UIViewController, title:String, imageName:String){
//        vc = LRHomeTableViewController() // 不需要
        self.tabBar.tintColor = UIColor.orangeColor()  // 可以直接修改整个控件的颜色
        
        // 实例化导航控制器
        let nav = UINavigationController(rootViewController: vc )
        // 1|图片
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
//        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal) // 图片命名很规范
        // 2|文字
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //        title = "首页"
        //        nav.title = "首页"
        // 添加
        addChildViewController(nav)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
